package com.ziyia.fragmentbestpractice;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import org.w3c.dom.Text;

public class NewsContentFragment extends Fragment {
//    @Nullable
//    @org.jetbrains.annotations.Nullable
//    @Override
//    public View onCreateView(@NonNull @org.jetbrains.annotations.NotNull LayoutInflater inflater, @Nullable @org.jetbrains.annotations.Nullable ViewGroup container, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
//        return inflater.inflate(R.layout.news_content_frag, container, false);
//    }
//
//
//    public void refresh(String title, String content) {
//        Activity activity = getActivity();
//
//        LinearLayout linearLayout =activity.findViewById(R.id.contentLayout);
//        TextView t = activity.findViewById(R.id.newTitle);
//        TextView c = activity.findViewById(R.id.newsContent);
//
//        linearLayout.setVisibility(View.VISIBLE);
//        t.setText(title);
//        c.setText(content);
//
//    }

    private View view;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.news_content_frag, container, false);
        return view;
    }
    public void refresh(String newsTitle, String newsContent) {
        View visibilityLayout = view.findViewById(R.id.contentLayout);
        visibilityLayout.setVisibility(View.VISIBLE);
        TextView newsTitleText = (TextView) view.findViewById (R.id.news_title);
        TextView newsContentText = (TextView) view.findViewById(R.id.newsContent);
        newsTitleText.setText(newsTitle); // 刷新新闻的标题
        newsContentText.setText(newsContent); // 刷新新闻的内容
    }
}
